const util = require("./util");
const methodsToPatch = [
    'push',
    'pop',
    'shift',
    'unshift',
    'splice',
    'sort',
    'reverse'
  ]
class XArray {
    constructor() {
        Array.apply(this, arguments);   
        return new Array();
    }
    
}
XArray.prototype= new Array();
class RubArray extends XArray {
    constructor(call,arr){
        super()
        let _this=this;
        this._$call=call
        for(var i=0;i<arr.length;i++){
            this[i]=arr[i]
        }
        // this._$set=function(i,val){
        //     _this[i,val]
        //     _this.call();
        // }
        methodsToPatch.forEach(method=>{
            const original = this[method]
            Object.defineProperty(this,method,{
                enumerable: false,
                configurable: true,
                get(...args){
                    _this._$call(util.copyArr(this));
                    return original
                }
            })
        })
    }
}




module.exports = RubArray;